<template>
  <div class="page" style="">
    <div class="print_title">预立项申请详情 · 禾美协同办公</div>
    <p class="title">基本信息</p>
    <a-row type="flex" justify="start" class="content" style="padding: 0 9px;">
      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap" >单据编号:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.billNo }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12">
        <a-row>
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap" >申请人:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.proposer_dictText }}</p>
          </a-col>
        </a-row>
      </a-col>

      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap" >申请部门:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.proposerDeptId_dictText }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap" >申请时间:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.createTime }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap" >项目名称:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.mc }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap" >经营团队:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.ywtd_dictText }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap" >项目承接人:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.cjr_dictText }}</p>
          </a-col>
        </a-row>
      </a-col>
      <!-- <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap" >是否投标、报价:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.sfztb_dictText }}</p>
          </a-col>
        </a-row>
      </a-col> -->
      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap" >是否环评项目:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.sfhpxm_dictText }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap" >签订单位:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.qddw_dictText }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap" >业绩归属年度:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.yjgsnd_dictText }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap" >业主单位:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.yzdw_dictText }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap" >联系人:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.lxr_dictText }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap" >联系电话:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.lxdh }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap" >项目所在地址:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ getAddress(formData.ssq) }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap" >项目所在详细地址:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.projectAddress }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap" >项目来源:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.xmly_dictText }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap" >预计合同额(元):</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.yjhte }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap" >大写:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.dx }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="24">
        <a-row>
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap" >立项事由及说明:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.lxsyjsm }}</p>
          </a-col>
        </a-row>
      </a-col>
    </a-row>

    <a-row type="flex" justify="center" v-if="formData.serviceList && formData.serviceList.length">
      <a-col>
        <p class="title_table">业务明细</p>
      </a-col>
      <a-col :span="24">
        <a-table
          :columns="columns"
          :data-source="formData.serviceList"
          bordered
          :pagination="false"
          size="small"
          :rowClassName="tableRowClass"></a-table>
      </a-col>
    </a-row>
    <a-row type="flex" justify="start" class="content" style="padding: 0 9px;">
      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap" >报价文件用印:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.isSeal_dictText }}</p>
          </a-col>
        </a-row>
      </a-col>
      <template v-if="formData.isSeal == '1'">
        <a-col :span="12">
          <a-row>
            <a-col style="display: flex;">
              <p style="margin-bottom: 0; white-space: nowrap" >用印类型:</p>
              <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.signSealWay_dictText }}</p>
            </a-col>
          </a-row>
        </a-col>

        <a-col :span="12">
          <a-row style="margin-bottom: 0">
            <a-col style="display: flex;">
              <p style="margin-bottom: 0; white-space: nowrap" >是否借出:</p>
              <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.lendYn_dictText }}</p>
            </a-col>
          </a-row>
        </a-col>
        <a-col :span="12">
          <a-row style="margin-bottom: 0">
            <a-col style="display: flex;">
              <p style="margin-bottom: 0; white-space: nowrap" >文件份数:</p>
              <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.quantity }}</p>
            </a-col>
          </a-row>
        </a-col>
        <a-col :span="12">
          <a-row style="margin-bottom: 0">
            <a-col style="display: flex;">
              <p style="margin-bottom: 0; white-space: nowrap" >用印说明:</p>
              <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.userExplain }}</p>
            </a-col>
          </a-row>
        </a-col>
        <a-col :span="12">
          <a-row style="margin-bottom: 0">
            <a-col style="display: flex;">
              <p style="margin-bottom: 0; white-space: nowrap" >选择印章:</p>
              <p style="margin:0 0 0 6px; word-break: break-all;">{{ sealIds_dictText }}</p>
            </a-col>
          </a-row>
        </a-col>
        <a-col :span="24" style="margin: 4px 0;" v-if="sealDataSource && sealDataSource.length">
        <a-table
          :columns="sealColumns"
          :data-source="sealDataSource"
          bordered
          :pagination="false"
          size="small"
          :rowClassName="tableRowClass">
          <span slot="sealType" :title="text" slot-scope="text, record">{{ record.sealType_dictText?record.sealType_dictText: record.sealType }}</span>
        </a-table>
      </a-col>
      </template>
    </a-row>
    <FileInfor :purchaseFile="signFile" title="用印文件" v-if="signFile && signFile.length && formData.isSeal ==1"></FileInfor>
    <!-- 附件信息 -->
    <FileInfor :purchaseFile="purchaseFile" v-if="purchaseFile && purchaseFile.length"></FileInfor>
    <!-- 流程详情 -->
    <ProcessInfor v-if="formData.bpmStatus !== '1'" :dataHistorySource="dataHistorySource"></ProcessInfor>
  </div>
</template>
<script>
import { getAction } from '@/api/manage'
import FileInfor from '@/components/print/FileInfor.vue' // 审批历史流程列表组件
import ProcessInfor from '@/components/print/ProcessInfor.vue' // 审批历史流程列表组件
import { filterMultiDictText, initDictOptions } from '@/components/dict/JDictSelectUtil'
import address from '@/components/AddressChoice/address.js'
export default {
	props: {
		formData: {
			type: Object,
			default: () => {},
			required: true
    },
		formDataHistory: {
			type: Object,
			default: () => {},
			required: true
    }
	},
  components: {
    FileInfor,
    ProcessInfor
  },
  data() {
    return {
      address,
      filterMultiDictText,
      dictOptions: {},
      dataSource: [], // 物料列表
      sealDataSource: [], // 印章列表
      sealColumns: [
        {
          title: '序号',
          dataIndex: '',
          key: 'rowIndex',
          width: 45,
          align: 'center',
          customRender: function (t, r, index) {
              return parseInt(index) + 1;
          }
        },
        {
          title: '印章编号',
          align: 'center',
          // width: 65,
          dataIndex: 'sealQualificationId'
        },
        {
          title: '名称',
          align: 'center',
          // width: 65,
          dataIndex: 'name'
        },
        {
          title: '印章类别',
          align: 'center',
          width: 65,
          dataIndex: 'sealType',
          scopedSlots: { customRender: 'sealType' }
        },
        {
          title: '印章管理员',
          align: 'center',
          // width: 65,
          dataIndex: 'handlerId'
        },
        {
          title: '申请部门',
          align: 'center',
          // width: 65,
          dataIndex: 'handlerDeptId'
        }
      ],
      columns: [
				{
					title: '序号',
					dataIndex: '',
					key: 'rowIndex',
					width: 45,
					align: 'center',
					customRender: function (t, r, index) {
						return parseInt(index) + 1;
					}
				},
				{
					title: '业务编码',
					align: 'center',
					dataIndex: 'serviceType'
				},
				{
					title: '业务名称',
					align: 'center',
					dataIndex: 'serviceName'
				}
			],
			dataHistorySource: [], // 流程列表
			url: {
				list: '/api/erp/purchase/procurement/erpPurchaseApplyInvitationDetail/allList', // 物料明细列表
        queryByIds: '/api/erp/administration/seal/erpSealCertificationChangeRecord/queryByIds2', // 印章列表
				historyList: '/api/erpmng/act/task/processHistoryList' // 流程历史跟踪接口
			},
      sealIds_dictText: '',
			purchaseFile: [], // 附件
      signFile: [] // 用印附件
    };
  },
	watch: {
		formData: {
			handler (val) {
				if (val) {
					this.initObj()
					this.getHistoryList()
          // this.initDictConfig() // 字典值
					if (val.xgfj) {
						this.purchaseFile = val.xgfj.split(',')
					}
					if (val.signFile) {
						this.signFile = val.signFile.split(',')
					}
				}
			},
			immediate: true
		},
		formDataHistory: {
			handler (val) {
				if (val) {
					this.getHistoryList()
				}
			},
			immediate: true
		}
	},
	methods: {
		// 获取列表
		getHistoryList() {
			var params = { processInstanceId: this.formDataHistory.procInsId };// 查询条件
			getAction(this.url.historyList, params).then(res => {
				if (res.success) {
					this.dataHistorySource = res.result.records || res.result
				}
			})
		},
    // 获取印章
    initObj() {
      this.sealIds_dictText = '';
      if (this.formData.sealIds && this.formData.sealIds.length > 0) {
        // sealIds = sealIds.split(',');
        let url = '';
        let param = {};
        url = this.url.queryByIds;
        param = { ids: this.formData.sealIds };
        getAction(url, param).then((res) => {
          if (res.success) {
            this.sealIds_dictText = '';
            this.sealDataSource = res.result // 印章列表
            if (res.result && res.result.length) {
              res.result.map((value, index) => {
                this.sealIds_dictText = (value.sealType_dictText ? value.sealType_dictText : value.sealType) + ',' + this.sealIds_dictText
              })
              this.sealIds_dictText = this.sealIds_dictText.substring(0, this.sealIds_dictText.length - 1)
            } else {
              this.sealIds_dictText = '';
            }
          }
        });
      }
    },

    initDictConfig() {
      initDictOptions('bidding_type').then((res) => {
        if (res.success) {
          this.$set(this.dictOptions, 'invitationManner', res.result)
        }
      })
    },

    getAddress (text) {
      if (!text) {
        return false
      }
      var areaList = text.split(',')
      var areaText = ''
      this.address.map(value => {
        if (areaList[0] && areaList[0] == value.code) {
          areaText = areaText + value.name + '/'
          if (value && value.children && value.children.length) {
            value.children.map(val => {
              if (areaList[1] && areaList[1] == val.code) {
                areaText = areaText + val.name + '/'

                if (val && val.children && val.children.length) {
                  val.children.map(va => {
                    if (areaList[2] && areaList[2] == va.code) {
                      areaText = areaText + va.name
                    }
                  })
                }
              }
            })
          }
        }
      })
      return areaText
    },

		list () {
			if (!this.formData.id) {
				return false
			}
			var params = {
				billId: this.formData.id
			}
			getAction(this.url.list, params).then(res => {
				if (res.success) {
						this.dataSource = res.result.records || res.result
						this.dataSource.forEach((item, index) => {
						item.key = index
					})
				}
      })
		},

		tableRowClass(record, index) {
			if (index == 0) {
				return 'rowClass';
			}
      return ''
    }
	}
};
</script>
<style lang="less" scoped>
.page{
	background: #ffffff;
	padding: 19px 28px 0 28px;
	width: 750px;
	.print_title{
		font-size: 15px;
		font-family: Alibaba PuHuiTi 2.0;
		font-weight: normal;
		color: #000000;
		display: flex;
		align-items: center;
		justify-content: center;
		margin-bottom: 9px;
	}
	.title {
		background: #EEEEEE;
		font-size: 13px;
		font-family: Alibaba PuHuiTi 2.0;
		font-weight: normal;
		color: #000000;
		padding: 11px 9px;
	}
	.title_table{
		font-size: 13px;
		font-family: Alibaba PuHuiTi 2.0;
		font-weight: normal;
		color: #000000;
	}
}
/deep/ .rowClass{
	font-size: 10px;
	font-family: Alibaba PuHuiTi 2.0;
	font-weight: normal;
	color: #000000;
}
/deep/ .ant-table-thead th{
	font-size: 10px;
	font-family: Alibaba PuHuiTi 2.0;
	font-weight: normal;
	color: #000000;
}
/deep/ .ant-table-thead tr{
	background: #EEEEEE;
}
/deep/ .ant-table-small > .ant-table-content > .ant-table-body {
    margin: 0 0px;
}
/deep/ .ant-table-body tr {
	font-size: 10px;
	font-family: Alibaba PuHuiTi 2.0;
	font-weight: normal;
	color: #000000;
}
/deep/ .ant-table-body tr td {
    word-wrap:break-word;
    word-break:break-all;
  }
  .content{
  font-size: 13px;
}
</style>
